package com.gym.code.generator.impl.degelate.method;

import static com.gym.code.generator.Contants.$tab;
import static com.gym.code.generator.utils.GenerateFileUtils.generateChar;

import java.util.ArrayList;
import java.util.List;

import com.gym.code.generator.model.mapping.field.EnumFieldGenerateModel;
import com.gym.code.generator.model.mapping.field.FieldGenerateModel;

/**
 * 
 * @author xinchun.wang 
   @email: 532002108@qq.com
 * @createTime 2015-5-23 下午8:45:48
 */
public class SetMethodGenerateHandlerImpl implements
		BeanMethodGenerateHandler {

	
	private SetMethodGenerateHandlerImpl() {
	}

	private static SetMethodGenerateHandlerImpl instance = new SetMethodGenerateHandlerImpl();

	public static SetMethodGenerateHandlerImpl getInstance() {
		return instance;
	}
	
	@Override
	public List<String> generateMethod(FieldGenerateModel model) {
		List<String> result = new ArrayList<String>();
		result.add("");
		result.add(generateChar(1,$tab) + "public void set" + model.getPropertyNameByFirstLetterUpper() + "(" + 
		(model.getValueType().isJdkDefine() ? model.getValueType().getName(): model.getValueType().getJavaName() )
		+" "+model.getPropertyName() +") {");
		result.add(generateChar(2,$tab)+"this." + model.getPropertyName()+" = "+model.getPropertyName()+";");
		result.add(generateChar(1,$tab)+"}");
		
		if(model instanceof EnumFieldGenerateModel){
			EnumFieldGenerateModel enumModel = (EnumFieldGenerateModel)model;
			result.add("");
			result.add(generateChar(1,$tab) + "public void set" + enumModel.getPropertyNameByFirstLetterUpper() + "(int value) {");
			result.add(generateChar(2,$tab)+"this." + enumModel.getPropertyName()+" = "+enumModel.getValueType().getJavaName()+".getInstanceById(value);");
			result.add(generateChar(1,$tab)+"}");
		}
		return result;
	}

}
